<template>
  <list-condition-template
    ref="table"
    :rows="rows"
    :defaultSort="{ prop: 'createTime', order: 'descending' }"
    :total="total"
    @page-info-change="handlePageInfoChange"
    :search-data="listQuery"
    :batch-column="false"
  >
    <template slot="condition">
      <el-form-item prop="keyword">
        <el-input
          placeholder="名称"
          v-model="listQuery.keyword"
          clearable
        ></el-input>
      </el-form-item>
    </template>

    <template slot="normalOperation">
      <el-form-item>
        <el-button
          class="filter-item"
          @click="handleCreate"
          type="success"
          icon="el-icon-plus"
          v-waves
          >新增</el-button
        >
      </el-form-item>
    </template>

    <template slot="columns">
      <el-table-column
        label="分类名"
        min-width="160"
        align="center"
        property="name"
        fixed
      ></el-table-column>
      <el-table-column
        label="商品数"
        min-width="100"
        align="center"
        property="categoryCount"
      ></el-table-column>
      <el-table-column
        label="备注"
        min-width="150"
        align="center"
        property="memo"
      ></el-table-column>
      <el-table-column
        label="创建日期"
        sortable="custom"
        min-width="150"
        align="center"
        property="createTime"
      ></el-table-column>
      <el-table-column
        align="center"
        label="详情"
        class-name="fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="showDetail(scope.row)"
            v-waves
            >查看</el-button
          >
        </template>
      </el-table-column>
    </template>
  </list-condition-template>
</template>

<script>
import categoryAPI from '@/api/goodsCategory'
import waves from '@/directive/waves' // 水波纹指令
import ListConditionTemplate from '@/components/templates/listConditionTemplate'

export default {
  directives: {
    waves
  },
  components: {
    ListConditionTemplate
  },
  data () {
    return {
      selectLoading: false,
      rows: [],
      total: 0,
      dateArray: [],
      listQuery: {},
      levels: []
    }
  },
  methods: {
    /**
     * 加载数据
     */
    getList (pageInfo) {
      categoryAPI
        .getPaged({ condition: this.listQuery, pageInfo })
        .then((response) => {
          console.log('res', response)

          this.rows = response.data.content
          this.total = response.data.totalElements
        })
    },
    /**
     * 搜索条件变更处理
     */
    handleFilter () {
      this.$refs.table.changeCondition()
    },
    /**
     * 分页信息变动事件处理
     * @param  {Object} pageInfo 分页信息
     */
    handlePageInfoChange (pageInfo) {
      this.getList(pageInfo)
    },
    /**
     * 查看详情点击处理
     * @param {*} row 参数
     */
    showDetail (row) {
      this.$router.pushTo(this.$router.routesConfig.categoryInfo, row.id)
    },
    /**
     * 新增
     */
    handleCreate () {
      this.$router.pushTo(this.$router.routesConfig.categoryInfo)
    }
  }
}
</script>
